package com.qyhl.module_practice.rank;


import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.civilized.PracticeRankBean;

public class PracticeRankModel implements PracticeRankContract.PracticeRankModel {
    private PracticeRankPresenter mPresenter;

    PracticeRankModel(PracticeRankPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getData(String insId, int type) {

        EasyHttp.get(PracticeUrl.GET_PRACTICE_RANK)
                .params("insId", insId)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("type", type + "")
                .execute(new SimpleCallBack<PracticeRankBean>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！");
                        } else {
                            mPresenter.setError("获取列表失败，请重新尝试！");
                        }
                    }

                    @Override
                    public void onSuccess(PracticeRankBean practiceRankBean) {
                        mPresenter.setData(practiceRankBean);
                    }
                });
    }
}
